import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/Login";
import Blogs from "@/views/Blogs";
import BlogDetail from "@/views/BlogDetail";
import BlogEdit from "@/views/BlogEdit";

Vue.use(VueRouter)

const routes = [
    {
      path: '/',
      name: 'index',
      redirect: {name:'blogs'}//重定向到Blogs页面，没啥用，顺手练
    },
   {
    path: '/login',
    name: 'Login',
    component: Login
  },{
    path: '/blog/all',
    name: 'blogs',
    component: Blogs
  },{/*url开头相同，静态路径要写在动态路径前*/
    path: '/blog/add',
    name: 'BlogAdd',
    component: BlogEdit,
    //表示需要认证（登录）
    meta: {
      requireAuth: true
    }
  },{
  /*注意这个要在/blog/:blogId/edit  url前，url头一样的时候，谁短谁在前*/
    path: '/blog/:blogId',
    name: 'BlogDetail',
    component: BlogDetail,
    props:true
  },/*注意这个blogId动态参数位置*/
  {
    path: '/blog/:blogId/edit',
    name: 'BlogEdit',
    component: BlogEdit,
    props: true,
    meta:{
      requireAuth:true
    }
  },
    
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
